package com.fenqile.api.pop.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.fenqile.api.pop.parameter.FQLBaseParam;
import com.fenqile.api.pop.parameter.FenqileSKUPopBean;
import com.fenqile.api.pop.parameter.FenqileSkuItems;
import com.fenqile.api.pop.parameter.Product;
import com.fenqile.api.pop.service.FenqileSKUPopCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.FQLOpenCallService;
import com.ymttest.database.model.thirdpartysync.fenqilebrand;
import com.ymttest.database.model.thirdpartysync.fenqilecategory;
import com.ymttest.database.model.thirdpartysync.fenqileproduct;
import com.ymttest.database.model.thirdpartysync.fenqilesku;

import sun.util.logging.resources.logging;
/**
*分期乐SKU操作Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FenqileSKUPop{
	private static FenqileSKUPopBean fenqileskupopBean;
	private static FenqileSKUPopCall fenqileskupopCall;
	private static FQLBaseParam FQLBaseParam;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分期乐SKU操作Test");
	}

	@Before
	public void caseUp() {
		fenqileskupopBean=new FenqileSKUPopBean();
		fenqileskupopCall=new FenqileSKUPopCall();
		FQLBaseParam=new FQLBaseParam();
		FQLBaseParam.setFormat("json");
		FQLBaseParam.setPartner_id(FQLOpenCallService.PartnerId);
		FQLBaseParam.setV("1.3");
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(fenqileskupopCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FenqileSKUPop_001() {
		Logger.start(true,"分期乐sku查询，与数据库对比---《品牌id与品牌不一致》，成功");
		try {
			
			//添加分期乐商品获取sku
			Map<String, Object> maps = FQLOpenCallService.getFenqiLeSku();
			fenqileproduct fqlproduct=(fenqileproduct) maps.get("fenqileproduct");
			fenqilesku fqlesku=(fenqilesku) maps.get("fenqilesku");
			fenqilecategory fqlecategory=(fenqilecategory) maps.get("fenqilecategory");
			fenqilebrand fqlebrand=(fenqilebrand) maps.get("fenqilebrand");
			Product Product=(Product) maps.get("searchFenqileSync");
			
			//根据skuid查询全部字段
			fenqileskupopBean.setFields("sku_id,product_id,product_name,brand_id,brand_name,category_id,category_name,spec,sku_num,sku_sell_num,amount,mart_amount,sku_status,create_time,modify_time,delivery_time,sku_pic,third_sku_id,start_time,end_time,delivery_type,sku_property,wareroom_list");
			fenqileskupopBean.setSku_ids(fqlesku.getFqlSkuId());
			fenqileskupopBean.setThird_sku_ids("");
			Logger.debug(FQLOpenCallService.FenqilePopCall("fenqile.sku.detail.get", fenqileskupopBean));
			List<FenqileSkuItems> fenqilePopCallToSKUObject = FQLOpenCallService.FenqilePopCallToSKUObject("fenqile.sku.detail.get", fenqileskupopBean);
			//获取到sku列表，与数据库对比查询
			fenqilePopCallToSKUObject.forEach(b->{
				Logger.verifyEquals(b.getSku_id(), fqlesku.getFqlSkuId(),"判断skuId");
				Logger.verifyEquals(b.getProduct_id(), fqlesku.getFqlProductId(),"判断productId");
				Logger.verifyEquals(b.getBrand_id(),Product.getBrandId() ,"判断brandId");
				Logger.verifyEquals(b.getBrand_name(), Product.getBrandName(),"判断brandName");
				Logger.verifyNotEquals(b.getBrand_id(), fqlebrand.getFqlBrandId(),"错误---判断brandId");
				Logger.verifyNotEquals(b.getBrand_name(), fqlebrand.getFqlBrandName(),"错误---判断brandName");
				Logger.verifyEquals(b.getCategory_id(), fqlecategory.getFqlCategory1Id()+"|"+fqlecategory.getFqlCategory2Id()+"|"+fqlecategory.getFqlCategory3Id(),"判断catagoryId");
				Logger.verifyEquals(b.getCategory_name(), fqlecategory.getFqlCategory1Name()+"|"+fqlecategory.getFqlCategory2Name()+"|"+fqlecategory.getFqlCategory3Name(),"判断catagoryName");
//				Logger.verifyEquals(b.getSpec(), fqlecategory.get,"判断brandName");
				Logger.verifyEquals(b.getSku_num()+"", fqlesku.getYmtStock(),"判断sku_num");
				Logger.verifyEquals(b.getAmount(), fqlesku.getFqlPrice().stripTrailingZeros().toPlainString(),"判断amount");
				Logger.verifyEquals(b.getSku_status(), fqlesku.getSyncStatus()==1?"已上架":"未上架","判断sku_status");
				
				System.out.println(Product);
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}